'''
@Company: TWL
@Author: xue jian
@Email: xuejian@kanzhun.com
@Date: 2020-01-16 18:07:40
'''
import os
import sys
import json
sys.path.append(os.path.abspath(os.path.join(os.path.dirname('__file__'), os.path.pardir)))

import thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from hulk_proxy.HulkProxyServ import Client
from scan_data.ttypes import ScanData

__HOST = "172.21.32.54"
__PORT = 10088

try:
    tsocket = TSocket.TSocket(__HOST, __PORT)
    transport = TTransport.TFramedTransport(tsocket)
    protocol = TBinaryProtocol.TBinaryProtocol(transport)
    client = Client(protocol)

    transport.open()
    '''
    @note: read model names
    '''
    models = client.hgetall('feature_meta')
    # print(models)
    for k, v in models.items():
        # print(k,v)
        
        f = open('./feature/' + k + '.json', 'w')
        print('write the feature/' + k + '.json file.')
        v_store = json.dumps(v)
        # print(v_store)
        # v_store = v_store.replace('], "', '],\n"')
        # v_store = v_store.replace('}, "', '},\n"')
        f.write(v)
        f.close()
    


    transport.close()
except thrift.Thrift.TException as ex:
    print(ex.message)